<?php

/**
 * This file holds the library functions for connecting database.
 * 
 * @package Database
 */
 
 
 /** 
 * Holds the MySQL link identifier to current database connection.
 * @global resource $g_db_connection
 */ 
 $g_db_connection = NULL;
 
 
 
 /**
 * Connect to database.
 * 
 * If $g_db_connection is not already set, make connection to database and set global variable $g_db_connection to MySQL link identifier.
 *
 * @return	bool	TRUE on success, FALSE on failure.
 */
 
 
function db_connect(){
	
	global $db_connection;
	
	
	if(!$db_connection){
		require("conf/db_config.php");
		$db_connection = mysql_connect($db_server, $db_username, $db_password) or die(mysql_error());
		mysql_query("SET NAMES 'utf8'");
		mysql_query("SET CHARACTER SET UTF8");
		mysql_query("SET time_zone = '+8:00';");

		mysql_select_db($db_name) or die(mysql_error());
		
		return TRUE;
	}

	return FALSE;
}


